<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%   
String path = request.getContextPath();   
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
%> 
<!DOCTYPE html>
<html>
<head>
    <title>最新动态</title>
    <base href="<%=basePath%>"> 
    <link rel="shortcut icon" href="<%=basePath%>img/favo.ico">
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/todc-bootstrap.css" rel="stylesheet">
    <link href="css/global.css" rel="stylesheet">
    <link href="css/layout.css" rel="stylesheet">
    <link href="css/user.css" rel="stylesheet">
    <link href="css/main.css" rel="stylesheet">
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/attension.js"></script>
</head>

<body>
<jsp:include page="include/topbar.jsp"></jsp:include>
<jsp:include page="include/logobar.jsp"></jsp:include>
<div class="layout grid-s5m0">
	<div class="col-sub user-nav">
		<jsp:include page="include/usernav_c.jsp"></jsp:include>
	</div>
	<div class="main-wrap">
		<div class="box user-bd">
			<div class="tl" style="height:auto;">
				<h3 style="margin-top:30px;">
					简介:<span class="saved"><font>${user.profile}<c:if test='${user.profile==null or user.profile==""}'>这家伙很懒，什么也没留下...</c:if></font></span>
				</h3>
				<h3>
					<span class="saved"><font>职业:&nbsp;${user.profession }<c:if test="${user.profession==null or user.profession=='' }">游民</c:if></font>&nbsp;&nbsp;&nbsp;主页:&nbsp;
					<c:choose>
						<c:when test="${user.privateUrl==null or  user.privateUrl==''}">
							<a href="<%=com.constant.ParamUtil.domain %>c/home/${user.id }.html"><%=com.constant.ParamUtil.domain %>c/home/${user.id }.html</a>
						</c:when>
						<c:otherwise>
							<a href="<%=com.constant.ParamUtil.domain %>${user.privateUrl }.html"><%=com.constant.ParamUtil.domain %>${user.privateUrl }.html</a>
						</c:otherwise>
					</c:choose>
					</span>
				</h3>
				<h3>
					<span class="saved"><font>答案:&nbsp;</font></span>${user.answersNum+0 }&nbsp;
					<span class="saved"><font>短文:&nbsp;</font></span>${user.articleNum+0 }&nbsp;
				</h3>
			</div>
			<div style="clear:both"></div>
			<div class="bd">
				<div class="tagsinput">
					<span id="taglist">
						<c:forEach var="tag" items="${tags }">
							<span class="badge tag">&nbsp;${tag.name }&nbsp;</span>
		                </c:forEach>
	                </span>
                </div>
                
                <div class="timeline" id="timeline">
                	<div class="event box">
                		<div class="hd tl">
                			<h3>
                			答案<span class="saved">[&nbsp;共${questions.allRow }条&nbsp;]</span>
                			</h3>
                		</div>
                		<c:choose>
                			<c:when test="${sessionScope.user!=null }">
                			<div class="input-append ask">
				              <input type="text" id="questionInput" class="span6" placeholder="问些什么吧">
				              <button type="button" class="btn btn-success" id="questionSubmit" onclick="askQuestion(this)">问</button>
				            </div>
				            <label class="checkbox"><input id="isAnonymous" type="checkbox"> 匿名</label>
                			</c:when>
                			<c:otherwise>
                				<span style="color:#999999"><a href="user/login.html?redirect=<%=basePath  %>c/home/${user.id }.html">登录</a>后给他留个问题哦？</span>
                			</c:otherwise>
                		</c:choose>
                		
			            <hr>
                		<div class="bd">
                		<c:forEach var='map' items='${questions.list }'>
	              			<div class='question event'>
							  <div class='head'>
							  		<img src='upload/head/${map.user_head }?s=50' onerror='this.src="upload/head/default.jpg?s=50"'/>
							  		<c:choose>
						 				<c:when test="${map.is_anonymous==0 }">
						 					<a href="c/home/${map.user_by_id }.html"><img src='upload/head/${map.user_by_head}?s=50' onerror='this.src="upload/head/default.jpg?s=50"'/></a>
						 				</c:when>
						 				<c:otherwise>
						 					<img src='upload/head/anony.jpg?s=50' onerror='this.src="upload/head/default.jpg?s=50"'/>
						 				</c:otherwise>
						 			</c:choose>
							 		
							 		<span class='action'>答</span>
							 		<c:if test="${map.is_public==0 }">
					 					<span class='lock'><img src="img/lock.gif" title='不公开'/></span>
					 				</c:if>
							  </div>
							  <div class='body'>
							 	<div class='hd'>
							 		<p>
							 			<span class='name'>${map.user_name}</span>
							 			<span>&nbsp;答&nbsp;</span>
							 			<c:choose>
							 				<c:when test="${map.is_anonymous==0 }">
							 					<span class='name'><a href="c/home/${map.user_by_id }.html">${map.user_by_name}</a></span>
							 				</c:when>
							 				<c:otherwise>
							 					<span class='name'>路人甲:</span>
							 				</c:otherwise>
							 			</c:choose>
							         ${map.question }
							 		</p>
							 	</div> 
							 	<div class='bd'>
							 		<p>
							 			${map.answer }
							 		</p>
							 	</div>
							 	<div class='ft'> 
							 		<p> 
							 			<span class='date'> 
							 				${map.question_at }
							 			</span> 
							 			<span class='action up' onclick="doAction('question','agree',${map.id },this)"> 
							 				顶(<em>${map.agree_num }</em>) 
							 			</span> 
							 			<span class='action down' onclick="doAction('question','disagree',${map.id },this)"> 
							 				踩(<em>${map.disagree_num }</em>) 
							 			</span> 
							 			<span class='action' onclick="doAction('question','collect',${map.id },this)"> 
							 				收藏(<em>${map.collect_num }</em>) 
							 			</span> 
							 			<span class='action' onclick="doAction('question','favor',${map.id },this)"> 
							 				喜欢(<em>${map.favor_num }</em>) 
							 			</span> 
							 			<span class='action comment'> 
							 				<a href="c/q/${map.id }.html">评论(<em>${map.comments_num }</em>)</a> 
							 			</span> 
							 		</p> 
							 	</div> 
							 </div> 
						 	</div> 
	               		</c:forEach>
                		</div>
                	</div>
					<div class="pagination pagination-centered">
					<ul>
						<c:if test="${questions.hasPreviousPage == true}">
							<li><a href="c/answerd/${user.id }.html?page=${questions.currentPage-1 }">上一页</a></li>
						</c:if>
						<c:forEach var="x" begin="${questions.startPage }" end="${questions.endPage }" step="1"> 
							<li <c:if test="${x==questions.currentPage }">class="disabled"</c:if>><a href="c/answerd/${user.id }.html?page=${x }">${x }</a></li>
						</c:forEach>
						<c:if test="${questions.hasNextPage ==true }">
							<li><a href="c/answerd/${user.id }.html?page=${questions.currentPage+1 }">下一页</a></li>
						</c:if>
						
					</ul>
				</div>
                </div>
			</div>
		</div>
	</div>
</div>
<input type="hidden" value="<%=basePath%>" id="baseUrl"/>
<jsp:include page="include/foot.jsp"></jsp:include>
</body>
<script type="text/javascript">
var count=0;
$(document).ready(function(){
	$('#questionInput').keydown(function(event){
        if(event.keyCode==13){
       	 $("#questionSubmit").click();
        }
   });
	
});
	function askQuestion(element){
		var customerId = ${user.id };
		var question = $("#questionInput").val();
		var isAnonymous = $("#isAnonymous").attr("checked")==="checked";
		if($.trim(question)===""){
			alert("问些什么吧");
			return;
		}
		var data = {question:question,isAnonymous:isAnonymous,customerId:customerId};
		$.ajax({
			type: "POST",  
	        url:"<%=basePath%>c/ask-question.json",
	        contentType : 'application/json',
            data:JSON.stringify(data),
            dataType:'json',
			success: function(response){ 
	        	if(response){
	        		if(response.ok){
	        			count++;
	        			$("#questionInput").val('');
	        			$(element).html("再问一个("+count+")");
	        			$(element).tooltip({'title':'提问成功','trigger':'manual'});
        				$(element).tooltip("show");
        				setTimeout(function(){$(element).tooltip("hide");},1000);
	        		}else{
	        			alert(response.msg);
	        		}
	        	}
	        },
		 	error: function(e){}
		});
	}
</script>
</html>